<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="../js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
var currentPage = ${currentPage };
var totalPage = ${totalPage };
$(document).ready(function(){
	$(".page:first").click(function(){
		currentPage = 1;
		getList();
	});
	$(".page:eq(1)").click(function(){
		if(currentPage==1){
			alert("当前已经是第一页啦");
		}else{
			currentPage--;
			getList();
		}
	});
	$(".page:eq(2)").click(function(){
		if(currentPage==totalPage){
			alert("当前已经是最后一页啦");
		}else{
			currentPage++;
			getList();
		}
	});
	$(".page:eq(3)").click(function(){
		currentPage = totalPage;
		getList();
	});
	$(":button:first").click(function(){
		currentPage = 1;
		getList();
	});
	function getList(){
		var namekey = $("#namekey").val();
		//var id = $("#goodsid").val();
		location.href="GetGoodsListServlet?currentPage="+currentPage+"&namekey="+namekey;
	}
});

function shop(id,goodsAccount){
	var num = $("#s").val();
	if(goodsAccount<num){
		alert("已经没有库存了");
	}else{
		goodsAccount-=num;
		alert(goodsAccount);
	}
	location.href="AddShoppingcartServlet?id="+id+"&num="+num+"&goodsAccount="+goodsAccount;

}
function order(id){
	var num = $("#order").val();
	location.href="AddOrderServlet?id="+id+"&num="+num;
}




function del(id){
	var num=$("#s").val();
	if(num<=1){
		alert("商品不能为0")
	}else{
		num--;
		$("#s").val(num);
	}
}
function add(id,account){
	var num=$("#s").val();
		if(num>=account){
			alert("商品不能大于库存")
		}else{
			num++;
			$("#s").val(num);
		}
		
		
<% 
   application.setAttribute("username", "凯哥");		
%>
		
		
}
</script>
</head>
<body>
<a href="GetGoodsListServlet">商城主页</a>
<a href="GetShoppingcartListServlet">我的购物车</a>
<a href="GetOrderListServlet">我的订单</a>
<a href="personalinfo.jsp">个人信息</a>
<br>
商品名称：<input type="text" id="namekey" value="${param.namekey}">
<input type="button" value="搜索">
<table border="1" width="80%">
	<tr><th>商品名称</th><th>价格</th><th>库存</th><th>店名</th>
		<th>老板</th><th>联系方式</th><th>数量</th><th>操作</th>
	</tr>
	<c:forEach items="${list}" var="b">
		<tr>
			<td>${b.goodsName}</td>
			<td>${b.goodsPrice}</td>
			<td>${b.goodsAccount}</td>
			<td>${b.user.userShopname}</td>
			<td>${b.user.userName}</td>
			<td>${b.user.userPhone}</td>
			<td>
				<img src="../img/delete.png" onclick="del(${b.goodsId})">
				<input id="s" value="1" size="1">
				<img src="../img/add.png" onclick="add(${b.goodsId},${b.goodsAccount})">
			</td>
			<td>
			    <input type="hidden" id="goodsid" value="${b.goodsId}" name="id">
				<input type="button" value="添加进购物车" id="shop" onclick="shop(${b.goodsId},${b.goodsAccount})">
				<input type="button" value="下单" id="order" onclick="order(${b.goodsId})">
			</td>
		</tr>
	</c:forEach>
</table>
<input type="button" value="第一页" class="page">
<input type="button" value="上一页" class="page">
<input type="button" value="下一页" class="page">
<input type="button" value="最后页" class="page">
${currentPage }/${totalPage }
</body>
</html>